<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Survey extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
        protected $week=1;
	protected $question_content="Nếu bây giờ có 100 triệu đồng trong tay, bằng cách nào bạn làm cho số tiền đó sinh lời?";
        protected $answer_list=array(
            array('title'=>"Đầu tư chứng khoán",'code'=>1),
            array('title'=>"Đầu tư BĐS",'code'=>2),        
            array('title'=>"Mua vàng",'code'=>3),
            array('title'=>"Gửi tiết kiệm ngân hàng",'code'=>4),
            array('title'=>"Cho vay lãi",'code'=>5),
            array('title'=>"Mở công ty",'code'=>6),
            array('title'=>"Khác",'code'=>7)
        );
        
            
        
        public function __construct()
	{
            parent::__construct();
            $this->load->model('chartinfo');
            $this->load->helper('url');
            
	}
        
        public function index()
	{
            //$this->load->view('survey_questions');
	}
        
        public function full()
	{
           $data['week'] =  $this->week;
           $data['question'] =  $this->question_content;
           $data['answer'] = $this->answer_list;
           $data['survey_title']="Khảo sát vui";
           
           $this->load->view('templates/default/header',$data);
           $this->load->view('survey_questions',$data);
           $this->load->view('templates/default/footer');    
	}
        
        public function next(){
            $this->chartinfo->add_response($this->answer_list,$this->week,1);
           redirect('/survey/answer','location',301);
        }
        
        public function answer($page=NULL){
            $result=$this->chartinfo->get_info($this->week,1);
            $data['chart_label']=  implode(",", $result["title"]);
            $data['chart_data']=implode(",", $result["value"]);
            //echo "<meta http-equiv='Content-Type' content='text/html;charset=utf-8' >";
            //echo $data['chart_value'].'<br>'.$data['chart_label'];
            $this->load->helper('url');
            $data['survey_title']="Kết quả khảo sát vui";
            $this->load->view('templates/default/header',$data);
            $this->load->view('survey_answer',$data);
            $this->load->view('templates/default/footer'); 
        }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */